Repository navigation
madmatrix GPU: FASTMATH=auto and SHAREDWF=auto, per-subprocess gates against calculate_jamps spills - #486
madmatrix GPU: FASTMATH=auto and SHAREDWF=auto, per-subprocess gates against calculate_jamps spills#486stloufra wants to merge 16 commits into
Conversation
Fast math per subprocess, kept unless approx div/sqrt grow jamps spill stack.
| @@ -352,7 +373,11 @@ else ifeq ($(BACKEND),hip) | |||
| GPUFLAGS += -target x86_64-linux-gnu -DHIP_PLATFORM=amd | |||
|
|
|||
| # Fast math (is -DHIP_FAST_MATH equivalent to -ffast-math?) | |||
There was a problem hiding this comment.
Would be nice to have a reply to this question?
There was a problem hiding this comment.
No. On AMD -DHIP_FAST_MATH is a no-op. We have discussed that in relation to Jorgens work some time ago. Changed.
| # more than FASTMATH_STACK_GROWTH bytes (fast-math benchmarks on L40S and H100): then -fmad is kept. | ||
| ifeq ($(FASTMATH),auto) | ||
| FASTMATH_STACK_GROWTH ?= 128 | ||
| override JAMPS_STACK = $(CUDA_HOME)/bin/cuobjdump -res-usage $(1) | awk '/Function .*calculate_jamps/ { getline; sub(/.*STACK:/, ""); if ($$1 + 0 > max) max = $$1 + 0 } END { print max + 0 }' |
There was a problem hiding this comment.
This seems to be CUDA-related but it is not gated, is it?
There was a problem hiding this comment.
It was gated only indirectly, by the error near the top when FASTMATH=auto is used without BACKEND=cuda. Made it explicit in 0984bc7: the rule now sits under ifeq ($(FASTMATH)$(BACKEND),autocuda) and the backend check is written out plainly. auto stays opt-in, the default remains FASTMATH=1 on every backend.
Hot wf slots by generator score in GPU shared mem, kept only where calculate_jamps spills without. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New macros use MADMATRIX prefix, no MGONGPU. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shorter name, no MG prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Template is %-formatted, bare 15% broke output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Discarded if constexpr still parsed on host HIP, __align__ undefined there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rule under autocuda, HIP_FAST_MATH comment answered (no-op on AMD).
336a532 to
0984bc7
Compare
Combined #484 + #486 + #491Whole UMAMI call, main at fabaad5 (before #484) against #484 + #486 + #491 (
Compile time. Clean builds of all 18 process × precision combinations,
|
|
@oliviermattelaer @theoheimel @Qubitol maybe we should discuss before we merge, so I am converting to draft for now. |
Turing 64 KB not 99 KB, unknown arch fall back to 48 KB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nwf counts calls, slots reused: ttggg 121 not 391, barrier only with shared slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fast math never picked there, dense arrays make its ptxas take over an hour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Smaller arrays, no barrier there: L40S FP64 ttggg 0.89x, ttgQQ 0.985x. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges mg5 3.8.2 57460b5 with 3.5.18 78fbcaa merged into it (4698ffa). Merge base baa636c (previous 3.8.x merge). Taken from upstream: - run_card: pdlabel stays user-defined when pdlabel1/2 are set internally (#481) - LO setcuts: smin no longer above the cut threshold (3.5.18: ihtmin, decay jets/leptons with ptjNmin/ptlNmin, cutuse=1, mmll/ptllmin/mmnl) - loop-induced madevent output with group_subprocesses=False (#486) - MadLoop (unoptimized output): loop filter keeps all amplitudes for 2>1 and 1>2 processes - symfact.dat symmetry factor assigned on every return path (auto_dsig) - RunCardLO.reset_simd: clean the compiled code when vector_size/nb_warp change (the hook was a no-op stub on main) - create_release.py: no macOS metadata in the release tarball (ported to MG7's rewritten script) - IOTests: TIR libraries pinned for the loop TIR_output and MatchBox tests - tests: smin below cut threshold, loop-induced ggh nogroup, ML loop filter across a boost, reset_simd; added to the CI bundles Kept from MadGraph7 (upstream change not applied): - genps.f/myamp.f: MG7 t-channel sampling (#323, msoft/tsoft); mg5 #466 relative-t and log map of the remaining s not taken - real-emission helicity ties: MG7 already removes the equal-helicity reuse at export (born_support.optimize_real_helicities); upstream's boosted re-check of T_IDENT and its test are superseded - LO vector mode without grouping and for decays (export_v4.py and the DSIG_VEC wrapper of auto_dsig_v4.inc): upstream's code has no IFLAV_VEC and does not fit MG7's flavour-aware vector interface - UpdateNotes.txt: MG7 notes only, no mg5 history - Pythia8 merging plugin, PY8Card plugins, LHAPDF 6.2 makefiles, density test tolerance: main already had the equivalent - IOTest goldens in conflict: kept at main's version Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compile time over L40S FP64 run time, FP64 not target there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi Frank, This sounds cool, but I'm worried to rush on this one, and has you said we need to discuss it. |
|
Ok. Won’t rush it, if you think it is premature. |
Picks follow amplitude count, GPU-independent outside band, 234 picks none missed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generator mask per barrier, bit per nSharedWf, constexpr no-op otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict in gpu SigmaKin.cc: keep shared-memory launch, main's comment.


Big
calculate_jampskernels sit at the 255-register cap and spill to local memory. Two opt-in, CUDA-only gates fight the spills per subprocess. Both measure the kernel just built, so nothing is tabulated per process, card or nvcc version. Defaults unchanged (FASTMATH=1,SHAREDWF=0).Includes #491 and #511 (merged here).
Mechanisms
FASTMATH=auto.-use_fast_mathcan be slower than strict: approximate div/sqrt remove the scheduling barriers of the precise calls, more values stay live and the spill stack grows (g g > t t~ g gf: 1312 → 2080 B). The gain is all from-fmad, the losses all from approximate div/sqrt.SigmaKin.ccbuilt twice,-fmad=trueand-use_fast_math.calculate_jampsstack (cuobjdump -res-usage) grows by ≤FASTMATH_STACK_GROWTH(128 B), else-fmad.SHAREDWF=auto. Wavefunctions ofcalculate_jampsin shared memory instead of spilled local memory.nSharedWfslots per thread, sized from the arch's shared-memory limit at compile time. Slots go to the wavefunctions with the most reads × lifetime.sw0) and with (sw1) shared slots, each with its own fast-math pick.sw1kept if thesw0stack exceedsSHAREDWF_STACK(128 B).SHWF_RELOAD) after an amplitude only where a shared slot is read again, else values stay in registers too. Per-barrier mask, constexpr no-op elsewhere:ttgggkeeps 819–1245 of 1890.Compile cost kept down.
ttggg: 121, not 391).f/v:-use_fast_mathbuild killed once-fmadspills >FASTMATH_MAD_STACK(4 KB). Fast math never won there.AUTO_PREDICT=1: picks follow the amplitude count, the same on every GPU outside a band (234 picks on L40S, H100, sm_70/80/100, none missed). Outside it only the predicted variant is compiled:dno shared memory below 10 amplitudes, shared above 30, always fast math.f/vno shared memory and fast math below 21, shared above 130,-fmadabove 300.Picks printed and saved in
build.cuda/SigmaKin.{fastmath,sharedwf}.Run time
ME wall throughput over main before #484 (fabaad5; #484 since merged, included here). Time summed over subprocesses, 10 interleaved repetitions, paired median. Launch 2048×256,
tt~ +3j256×256,W+W- +3j1024×256.dfvdfvdfvg g > t t~ g g g(H100 1.15–1.28×) andW+W- +3jd(1.03×).dtt~ +3j0.95: no shared slots for FP64 on sm_89, smaller arrays give more local loads. Accepted, L40S not for FP64.g g > t t~ g g g:f1.010×,v0.958× (spill code scheduled differently). Accepted for compile time.Correctness. #511 against #491: same picks, |M|² bitwise identical except
g g > t t~ g g g(≤ 2e-6f/v, ≤ 1.3e-14d, reordered spills), helicity and colour choices identical.Compile time
Clean build of
g g > t t~+ 0–3g,make -j8, CUDA 13.1, three builds side by side, single run. Main 3371e16 with defaults, this PRFASTMATH=auto SHAREDWF=auto. Wall / CPU s:dfvdfvWithout #511 (#486 + #491) the same build was 2.5–3.3× wall, 6.5–7.6× CPU over main.
Top: run time over main. Bottom: compile time over main, wall filled, CPU open.
🤖 Generated with Claude Code